<style lang="scss" scoped>
.my-popover-class {
  max-height: 300px; // 根据需要调整最大高度
  overflow-y: auto; // 允许垂直滚动
}

span.textname {
  display: block;
  width: 100%;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

/* 其他样式保持不变 */

.el-input.is-disabled ::v-deep .el-input__inner {
  color: #606266;
  background-color: #f5f7fa;
  border: none;
}

.el-textarea.is-disabled ::v-deep .el-textarea__inner {
  color: #606266;
  background-color: white;
  // border: none;
  // width: 500px;
  resize: none;
  cursor: pointer;
}
</style>
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="90px"
    >
      <!-- <el-form-item label="一级id" prop="commentFirstId">
        <el-input
          v-model="queryParams.commentFirstId"
          placeholder="请输入一级id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="评价归类" prop="secondLevelCategory">
        <el-input
          v-model="queryParams.secondLevelCategory"
          placeholder="请输入评价归类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="评价关键词" prop="threeLevelCategory">
        <el-input
          v-model="queryParams.threeLevelCategory"
          placeholder="请输入评价关键词"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
      <br />
      <el-form-item label="评价内容" prop="threeLevelCategory">
        <el-input
          style="width: 800px"
          v-model="commentContent"
          type="textarea"
          :autosize="{ minRows: 1, maxRows: 50 }"
          :disabled="true"
        />
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['comment:BiCommentSecondDwd:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['comment:BiCommentSecondDwd:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['comment:BiCommentSecondDwd:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['comment:BiCommentSecondDwd:export']"
          >导出</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="handleauditResultThreeCommentS"
          >智能复核</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="BiCommentSecondDwdList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="一级id" align="center" prop="commentFirstId" /> -->
      <el-table-column
        label="一级归类"
        align="center"
        prop="firstLevelCategory"
      />
      <el-table-column
        label="评价归类"
        align="center"
        prop="secondLevelCategory"
      />
      <el-table-column
        label="评价关键词"
        align="center"
        prop="threeLevelCategory"
      />
      <el-table-column label="智能复核结果" align="center" prop="auditResult" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['comment:BiCommentSecondDwd:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['comment:BiCommentSecondDwd:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改评价类型二级对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="90px">
        <!-- <el-form-item label="一级id" prop="commentFirstId">
          <el-input v-model="form.commentFirstId" placeholder="请输入一级id" />
        </el-form-item> -->

        <el-form-item label="一级归类" prop="firstLevelCategory">
          <el-input
            :disabled="isdisabled"
            v-model="form.firstLevelCategory"
            placeholder="请输入一级归类"
          />
        </el-form-item>
        <el-form-item label="评价归类" prop="secondLevelCategory">
          <el-input
            :disabled="isdisabled"
            v-model="form.secondLevelCategory"
            placeholder="请输入评价归类"
          />
        </el-form-item>
        <el-form-item label="评价关键词" prop="threeLevelCategory">
          <!-- <el-input
            v-model="form.threeLevelCategory"
            placeholder="请输入评价关键词"
          /> -->
          <el-select
            v-model="form.threeLevelCategory"
            placeholder="请输入评价关键词"
            filterable
            clearable
            @change="changethreeLevelCategory"
          >
            <el-option
              v-for="dict in threeLevelCategoryList"
              :key="dict.id"
              :label="dict.threeLevelCategory"
              :value="dict.threeLevelCategory"
            />
          </el-select>
          <el-button
            style="margin-left: 5px"
            type="primary"
            size="mini"
            @click="openInfo = true"
            >新增标签</el-button
          >
        </el-form-item>
        <el-form-item
          label="智能复核结果"
          prop="auditResult"
          label-width="100px"
        >
          <!-- <el-input
          v-model="queryParams.auditResult"
          placeholder="是否匹配"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
          <el-select
            v-model="form.auditResult"
            placeholder="智能复核结果"
            clearable
          >
            <el-option label="匹配" value="匹配" />
            <el-option label="不匹配" value="不匹配" />
            <el-option label="空白" value="空白" />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog
      :visible.sync="openInfo"
      width="1500px"
      append-to-body
      v-if="openInfo"
    >
      <BiCommentType @handleColse="handleColse" />
    </el-dialog>
  </div>
</template>

<script>
import BiCommentType from "@/views/comment/BiCommentType/index.vue";
import {
  listBiCommentSecondDwd,
  getBiCommentSecondDwd,
  delBiCommentSecondDwd,
  addBiCommentSecondDwd,
  updateBiCommentSecondDwd,
} from "@/api/comment/BiCommentSecondDwd";
import { listVo } from "@/api/comment/BiCommentType";
import {
  auditResultThreeCommentS,
  updateDataset,
} from "@/api/comment/BiCommentFirstDwd";
export default {
  name: "BiCommentSecondDwd",
  components: {
    BiCommentType,
  },
  props: {
    commentFirstId: {
      type: Number,
      default: null,
    },
    commentContent: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      isdisabled: true,
      commentFirstIdList: [],
      openInfo: false,
      threeLevelCategoryList: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 评价类型二级表格数据
      BiCommentSecondDwdList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        commentFirstId: null,
        secondLevelCategory: null,
        threeLevelCategory: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        commentFirstId: [
          { required: true, message: "一级id不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  beforeDestroy() {
    this.$emit("handleColse");
  },
  watch: {
    commentFirstId: {
      handler: function (newnew, oldold) {
        if (this.commentFirstId) {
          this.queryParams.commentFirstId = this.commentFirstId;
          this.getList();
        }
      },
      deep: true,
      immediate: true,
    },
  },
  methods: {
    handleauditResultThreeCommentS() {
      if (this.commentFirstIdList.length < 1) {
        this.$modal.msgError("至少选择一条数据");
        return;
      }
      auditResultThreeCommentS(this.commentFirstIdList).then((response) => {
        if (response.code == 200) {
          this.$modal.msgSuccess("智能复核成功");

          this.getList();
        }
      });
    },
    handleColse() {
      this.getlistVo();
      this.openInfo = false;
    },
    /** 查询评价类型二级列表 */
    getList() {
      this.loading = true;
      listBiCommentSecondDwd(this.queryParams).then((response) => {
        this.BiCommentSecondDwdList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        commentFirstId: null,
        secondLevelCategory: null,
        threeLevelCategory: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
      this.commentFirstIdList = selection.map((item) => item.commentFirstId);
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.form.commentFirstId = this.commentFirstId;
      console.log(JSON.stringify(this.form));
      this.isdisabled = false;
      this.open = true;
      this.title = "添加评价类型二级";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getBiCommentSecondDwd(id).then((response) => {
        this.form = response.data;
        this.isdisabled = true;
        this.open = true;
        this.title = "修改评价类型二级";
        this.getlistVo();
      });
    },
    getlistVo() {
      listVo().then((response) => {
        this.threeLevelCategoryList = response;
      });
    },
    changethreeLevelCategory() {
      this.threeLevelCategoryList.forEach((item) => {
        if (item.threeLevelCategory == this.form.threeLevelCategory) {
          this.form.secondLevelCategory = item.secondLevelCategory;
          this.form.firstLevelCategory = item.firstLevelCategory;
        }
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateBiCommentSecondDwd(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
              this.handleupdateDataset(this.form.commentFirstId);
            });
          } else {
            addBiCommentSecondDwd(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.isdisabled = true;
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除评价类型二级编号为"' + ids + '"的数据项？')
        .then(function () {
          return delBiCommentSecondDwd(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
          this.handleupdateDataset(row.commentFirstId);
        })
        .catch(() => {});
    },

    handleupdateDataset(commentFirstId) {
      updateDataset(commentFirstId).then((response) => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "comment/BiCommentSecondDwd/export",
        {
          ...this.queryParams,
        },
        `BiCommentSecondDwd_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>


